﻿<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>活动报名</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <link href="../Frozenui1.3/css/frozen.css" rel="stylesheet" />
    <link href="../JS/Date/FT_Date.min.css" rel="stylesheet" />
    <script src="../JS/layer/layer.m.js"></script>
    <script src="../JS/zepto.min.js"></script>
    <script src="../Frozenui1.3/js/frozen.js"></script>
    <script src="../JS/avalon.mobile.min.js"></script>
    <script src="../JS/MobileCom.js?v=1.1"></script>

    <script src="../JS/mobiscroll.zepto.js"></script>
    <script src="../JS/mobiscroll.core.js"></script>
    <script src="../JS/mobiscroll.scroller.js"></script>
    <script src="../JS/mobiscroll.datetime.js"></script>
    <script src="../JS/mobiscroll.i18n.zh.js"></script>
    
    <script src="../JS/jquery.autoTextarea.js"></script>

    <script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script>
        document.addEventListener('WeixinJSBridgeReady', function onBridgeReady() {
            //隐藏右上角按钮
            WeixinJSBridge.call('hideOptionMenu');
        });
        var strId = MobileCom.getQueryString("ID");

        var height = 0;
        var width = 0;

        var currYear = (new Date()).getFullYear();
        var opt1 = {
            date: { preset: 'date' },
            defaultopi: {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                lang: 'zh',
                startYear: currYear - 5, //开始年份
                endYear: currYear + 5, //结束年份
                onSelect: function (valueText, inst) {
                    //model.ctData.RBDate = valueText;
                }
            }
        };
        var opt2 = {
            date: { preset: 'datetime' },
            defaultopi: {
                theme: 'android-ics light', //皮肤样式
                display: 'modal', //显示方式
                mode: 'scroller', //日期选择模式
                lang: 'zh',
                startYear: currYear - 5, //开始年份
                endYear: currYear + 5, //结束年份
                onSelect: function (valueText, inst) {
                    //model.ctData.RBDate = valueText;
                }
            }
        };

        function fun1(str) {
            $("#hdsj").scroller($.extend(opt1['date'], opt1['defaultopi'])).scroller('setDate', str, true);
        }
        function fun2(str) {
            $("#hdjzsj").scroller($.extend(opt2['date'], opt2['defaultopi'])).scroller('setDate', str, true);
        }


        var model = avalon.define({
            $id: "hdmodel",
            isbj: "",
            ftData: [],
            sctp: function (scel) {
                model.ftData.remove(scel);
            },
            imgurl: "",
            wximg: "",
            ctData: { "HDFQF": "", "HDTime": "", "HDBMEndTime": "", "HDTitle": "", "HDAdress": "", "HDPeople": "", "isPublic": "", "HDContent": "","Files":"" },
            savedata: function () {
                if (model.ctData.HDFQF == "") {
                    $.tips({
                        content: "请输入发起方",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.HDTime == "") {
                    $.tips({
                        content: "请输入活动时间",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                else {
                    if (MobileCom.compareDate(model.ctData.HDTime, ""))
                    {
                        $.tips({
                            content: "活动时间必须大于今天",
                            stayTime: 2000,
                            type: "warn"
                        })
                        return;
                    }
                }
                model.ctData.HDBMEndTime = $("#hdjzsj").val();
                if (model.ctData.HDBMEndTime == "") {
                    $.tips({
                        content: "请输入报名截止时间",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                else {
                    if (MobileCom.compareTime(model.ctData.HDBMEndTime, "")) {
                        $.tips({
                            content: "报名截止时间必须大于当前时间",
                            stayTime: 2000,
                            type: "warn"
                        })
                        return;
                    }
                }
                if (model.ctData.HDTitle == "") {
                    $.tips({
                        content: "请输入活动主题",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.HDAdress == "") {
                    $.tips({
                        content: "请输入活动地址",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                if (model.ctData.HDContent == "") {
                    $.tips({
                        content: "请输入活动简介",
                        stayTime: 2000,
                        type: "warn"
                    })
                    return;
                }
                var lg = $.loading({
                    content: '保存中...',
                })
                model.ctData.Files = "";
                $("#imglist .tpli").each(function () {
                    if ($(this).hasClass("wximg")) { //微信上传未处理的图片
                        if (model.wximg) {
                            model.wximg += ",";
                        }
                        model.wximg += $(this).attr("itemid");

                    } else {
                        if (model.ctData.Files) {
                            model.ctData.Files = model.ctData.Files + ',' + $(this).attr("itemid");
                        }
                        else {
                            model.ctData.Files = $(this).attr("itemid");
                        }
                    }

                })
                $.post("/API/WXAPI.ashx?Action=ADDHDBM&r=" + Math.random(), { "P1": JSON.stringify(model.ctData.$model), "P2": model.wximg }, function (data) {
                    lg.hide();
                    var data = $.parseJSON(data);
                    if (data.ErrorMsg == "") {
                        $("button").hide();
                        var el = $.tips({
                            content: "保存成功！",
                            stayTime: 2000,
                            type: "success"
                        })
                        el.on("tips:hide", function () {
                            //window.location.reload();
                            if (model.isbj == "") {
                                window.location.replace(location.href);
                            }
                            else {
                                //window.location.replace("UI_HDBM_INFO.html?ID=" + strId + "&r=" + Math.random());
                                window.location.replace("UI_HDBM_LIST.html?r=" + Math.random());
                            }
                        })
                    }
                    else {
                        $.tips({
                            content: "保存失败，原因：" + data.ErrorMsg,
                            stayTime: 2000,
                            type: "warn"
                        })
                    }
                })
            },
            repshow: function () {
                $(this).parent().siblings().removeClass("active");
                $(this).parent().addClass("active");
            },
            selperson: function () {
                $("#content").hide();
                $("#iframep").show();

                var cheight = height;
                var cwidth = width;

                $("#iframep").css("height", cheight);
                $("#iframep").css("width", cwidth);

            },
            bjk: function () {

                var tc = layer.open({
                    type: 1,
                    //content:$("#bmxx").html(),
                    //title: "活动简介",
                    content: '<div class="ui-form-item ui-form-item-textarea ui-border-b" style="width:'+(width-76)+'px;height:200px"><textarea id="hdjjbjk" style="padding-left: 0;height:170px;border: 1px solid #e0e0e0;" placeholder="请输入活动简介">' + model.ctData.HDContent + '</textarea></div>',
                    btn: ['确认', '取消'],
                    shadeClose: false,
                    yes: function () {
                        model.ctData.HDContent = $("#hdjjbjk").val();
                        if ($("#hdjjbjk").val() != "") {
                            $("#hdjj").removeClass("ui-txt-muted");
                            $("#hdjj").html($("#hdjjbjk").val());
                        }
                        else {
                            $("#hdjj").addClass("ui-txt-muted");
                            $("#hdjj").html("请输入活动简介");
                        }

                        layer.close(tc);

                    }, no: function () {
                    }
                })
            }

        });

        function goback() {
            $("#content").show();
            $("#iframep").hide();
        }
        function goconfirm(json) {
            if (json != null) {
                $("#kh_fzry").removeClass("ui-txt-muted");
                $("#kh_fzry").html(json.vuser);
                model.ctData.HDPeople = json.vusername;
            }
            else {
                $("#kh_fzry").addClass("ui-txt-muted");
                $("#kh_fzry").html('请输入活动参与人');
                model.ctData.HDPeople = '';
            }

            $("#content").show();
            $("#iframep").hide();
        }

        avalon.ready(function () {
            height = document.documentElement.clientHeight;
            width = document.documentElement.clientWidth;
            $("#iframep").attr("src", "UI_PERSON.html?r=" + Math.random());
            if (!strId)
            {
                fun1(new Date(new Date().setDate(new Date().getDate() + 1)));
                fun2(new Date(new Date().setDate(new Date().getDate() + 1)));
                model.ctData.HDTime = $("#hdsj").val();
                model.ctData.HDBMEndTime = $("#hdjzsj").val();
            }
            
            if (strId) {
                model.isbj = "Y";
                $("#save").text("保存");
                $("title").text("修改活动报名");

                var lg = $.loading({
                    content: '加载中...',
                })
                
                $.getJSON('/API/WXAPI.ashx?Action=GETUSERHDBMLIST&Id=' + strId + '&r=' + Math.random(), {}, function (resultData) {
                    lg.hide();
                    if (resultData.ErrorMsg == "") {
                        model.ctData = resultData.Result[0];

                        var arr1 = model.ctData.HDTime.substring(0,10).split("-");
                        var time1 = new Date(arr1[0], arr1[1] - 1, arr1[2]);
                        //model.ctData.HDTime = time1;
                        var arr = model.ctData.HDBMEndTime.split(" ");
                        var arr2 = arr[0].split("-");
                        var arr3 = arr[1].split(":");
                        var time2 = new Date(arr2[0], arr2[1] - 1, arr2[2], arr3[0], arr3[1], arr3[2]);

                        fun1(time1);
                        model.ctData.HDTime = model.ctData.HDTime.substring(0, 10);

                        fun2(time2);
                        model.ctData.HDBMEndTime = model.ctData.HDBMEndTime.substring(0, 16);

                        if (model.ctData.HDContent != "" && model.ctData.HDContent != null) {
                            $("#hdjj").removeClass("ui-txt-muted");
                            $("#hdjj").html(model.ctData.HDContent);
                        }

                        if (resultData.Result[0].HDPeople != null) {
                            $("#iframep").attr("src", "UI_PERSON.html?r=" + Math.random() + "&Users=" + resultData.Result[0].HDPeople);
                            $.getJSON('/API/SZHLAPI.ashx?Action=GETUSERSBYUSERNAME&r=' + Math.random(), { P1: resultData.Result[0].HDPeople }, function (data) {
                                var html = "";
                                if (data.ErrorMsg == "") {
                                    for (var i = 0; i < data.Result.length;i++)
                                    {
                                        if (html == "") {
                                            html = data.Result[i].UserRealName;
                                        }
                                        else {
                                            html = html + "," + data.Result[i].UserRealName;
                                        }
                                    }
                                }
                                if (html != "")
                                {
                                    $("#kh_fzry").removeClass("ui-txt-muted");
                                    $("#kh_fzry").html(html);
                                }
                            })
                        }
                    }
                })
            }

            $(".chackTextarea-area").autoTextarea({
                maxHeight: 220,
                minHeight: 80
            });

            MobileCom.uploadimg();

            $.post("/API/SZHLAPI.ashx?Action=GetUserInfo&r=" + Math.random(), {}, function (data) {

                var data = $.parseJSON(data);
                if (data.ErrorMsg == "") {
                    if (data.Result.QYinfo.FileServerUrl) {
                        var str = data.Result.QYinfo.FileServerUrl;
                        if (str.substr(str.length - 1, 1) != "/") {
                            str = str + "/";
                        }
                        model.imgurl = str;
                    }
                }
            })
        })

        function back() {
            window.location.replace("UI_HDBM_LIST.html?r=" + Math.random());
        }
    </script>
    <style type="text/css">
        .ui-select {
            border: none;
            border: 0;
            background-color: #fff;
            appearance: none;
            -moz-appearance: none; /* Firefox */
            -webkit-appearance: none; /* Safari 和 Chrome */
        }
        .ms-controller, [ms-controller] {
            display: none;
        }
        .ui-form-item .wspan {
            width: 100%;
            display: -webkit-box;
            -webkit-box-sizing: border-box;
            box-sizing: border-box;
            -webkit-appearance: none;
            border: 0;
            background: 0 0;
            padding-left: 95px;
        }

            .ui-form-item .wspan img {
                width: 50px;
                height: 50px;
                padding-right: 3px;
            }

        .sctp {
            color: #18b4ed;
            right: 4px;
            top: -5px;
            z-index: 9;
            width: 20px;
            height: 20px;
            background: #fff;
            border-radius: 13px;
            line-height: 20px;
            text-indent: -3px;
            position: absolute;
            font-size: 25px;
        }

        .imgxl {
            position: relative;
            float: left;
            padding-top: 0;
            height: 50px;
            width: 50px;
            padding-right: 10px;
            margin-left: 0px;
            margin-bottom: 5px;
        }

        .tpxs {
            height: 50px;
            width: 50px;
            position: absolute;
            top: 0;
            left: 0;
            z-index: 1;
            background-repeat: no-repeat;
            -webkit-background-size: cover;
        }
    </style>
</head>
<body ms-controller="hdmodel">
    
    <div id="content">
        <header ms-if="isbj" class="ui-header ui-header-stable ui-border-b">
            <i class="ui-icon-return" onclick="back()"></i>
            <h1>活动信息修改</h1>
        </header>
        <div class="ui-footer ui-footer-stable ui-btn-group ui-border-t">
            <button class="ui-btn-lg" onclick="back()">
                取消
            </button>
            <button id="save" class="ui-btn-lg ui-btn-primary" ms-click="savedata()">
                新增活动
            </button>
        </div>

        <section class="ui-container">
            <div class="ui-form">
                <div class="ui-form-item ui-border-b">
                    <label>
                        发起方
                    </label>
                    <input type="text" placeholder="请输入发起方" ms-duplex="ctData.HDFQF" />
                </div>

                <div class="ui-form-item ui-border-b">
                    <label>
                        活动时间
                    </label>
                    <div class="ui-select ui-border-b">
                        <input type="text" placeholder="请输入活动时间" ms-duplex="ctData.HDTime" id="hdsj" style="padding-left:0" />

                    </div>
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        报名截止
                    </label>
                    <div class="ui-select ui-border-b">
                        <input type="text" placeholder="请输入报名截止时间" ms-duplex="ctData.HDBMEndTime" id="hdjzsj" style="padding-left:0" />

                    </div>
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        活动主题
                    </label>
                    <input type="text" placeholder="请输入活动主题" ms-duplex="ctData.HDTitle" />
                </div>
                <div class="ui-form-item ui-border-b">
                    <label>
                        活动地址
                    </label>
                    <input type="text" placeholder="请输入活动地址" ms-duplex="ctData.HDAdress" />
                </div>
                <div class="ui-form-item ui-border-b" style="height:auto">
                    <label>
                        活动参与人
                    </label>
                    <div class="ui-txt-muted ui-whitespace ui-form-item-link" style="padding-left: 95px;text-align:justify" id="kh_fzry" ms-click="selperson()">请输入活动参与人</div>

                </div>
                <!--<div class="ui-form-item ui-border-b">
                    <label>
                        是否公开
                    </label>
                    <label class="ui-switch" style="padding-left: 95px;right:auto">
                        <input type="checkbox" ms-duplex-radio="ctData.isPublic" />
                    </label>
                </div>-->
                <div class="ui-form-item ui-border-b ui-form-item-textarea" style="height:auto;min-height:44px">
                    <label>
                        活动简介
                    </label>
                    <textarea placeholder="请输入活动简介" style="height:80px;" class="chackTextarea-area" ms-duplex="ctData.HDContent"></textarea>
                    <!--<div class="ui-txt-muted ui-whitespace" style="padding-left: 95px;text-align:justify" id="hdjj" ms-click="bjk()">请输入活动简介</div>-->
                </div>
                <div class="ui-form-item ui-border-b" style="height:auto;min-height:44px">
                    <label>
                        上传图片
                    </label>

                    <div class="wspan" style="padding-top: 5px; height: auto;display:block">
                        <ul id="imglist">
                            <span ms-repeat-fl="ftData">
                                <li class="imgxl tpli" ms-attr-itemid="{{fl.ID}}" ms-if="MobileCom.xstp(fl.FileExtendName)">
                                    <span ms-css-background-image="url({{imgurl+'image/'+fl.FileMD5}})" class="tpxs"></span>
                                    <i class="ui-icon-close-progress sctp" ms-click="sctp(fl)"></i>
                                </li>
                            </span>
                            <span ms-repeat-fls="ftData">
                                <li class="imgxl tpli" ms-attr-itemid="{{fls.ID}}" ms-if="!MobileCom.xstp(fls.FileExtendName)">
                                    <span ms-css-background-image="url({{'/MobileView/Images/qywd/'+fls.FileExtendName+'.png'}})" class="tpxs"></span>
                                    <i class="ui-icon-close-progress sctp" ms-click="sctp(fls)"></i>
                                </li>
                            </span>
                            <li class="imgxl scli"><img id="add_pit" src="../Images/icon-add.png" /></li>
                        </ul>
                        <div style="clear:both"></div>
                    </div>
                </div>
            </div>
        </section>
    </div>


    <iframe id="iframep" src="UI_PERSON.html" style="display: none; margin-bottom: -7px;" frameborder="0" ></iframe>
</body>
</html>
